package com.koron.order.overhaul.service.impl;

import com.koron.common.core.util.CodeTools;
import com.koron.order.overhaul.bean.entity.OverhaulOrderReadyBean;
import com.koron.order.overhaul.bean.query.OverhaulOrderReadyQuery;
import com.koron.order.overhaul.mapper.OverhaulOrderReadyMapper;
import com.koron.order.overhaul.service.OverhaulOrderReadyService;
import com.koron.order.overhaul.utils.CommonUtils;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (OverhaulOrderReadyBean)表服务实现类
 *
 * @author twcao
 * @since 2021-09-29 09:49:34
 */
@Service
public class OverhaulReadyServiceImpl implements OverhaulOrderReadyService {

    @Override
    public OverhaulOrderReadyBean queryById(SessionFactory factory, String id) {
        OverhaulOrderReadyMapper mapper = factory.getMapper(OverhaulOrderReadyMapper.class);
        return mapper.queryById(id);
    }

    @Override
    public int saveOrUpdate(SessionFactory factory, List<OverhaulOrderReadyBean> beans) {
        OverhaulOrderReadyMapper mapper = factory.getMapper(OverhaulOrderReadyMapper.class);
        CommonUtils.update(beans);
        beans.stream().forEach(row -> row.setId(StringUtils.isBlank(row.getId()) ? CodeTools.getCode32() : row.getId()));
        return mapper.saveOrUpdate(beans);
    }

    @Override
    public int deleteByOrderId(SessionFactory factory, String orderId) {
        OverhaulOrderReadyMapper mapper = factory.getMapper(OverhaulOrderReadyMapper.class);
        return mapper.deleteByOrderId(orderId);
    }

    @Override
    public int hiddenByOrderId(SessionFactory factory, String orderId) {
        OverhaulOrderReadyMapper mapper = factory.getMapper(OverhaulOrderReadyMapper.class);
        return mapper.hiddenByOrderId(orderId);
    }

    @Override
    public List<OverhaulOrderReadyBean> queryList(SessionFactory factory, OverhaulOrderReadyQuery query) {
        OverhaulOrderReadyMapper mapper = factory.getMapper(OverhaulOrderReadyMapper.class);
        return mapper.queryList(query);
    }

}
